package com.qfedu.dao;

import com.qfedu.model.Taskplan;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface TaskplanDao {
    //根据bid查询
    @Select("select * from taskplan where status =1 and bid = #{bid}")
    List<Taskplan> findByBid(String bid);

    //添加
    @Insert("insert into taskplan (tname,starttime,endtime,bid,updatetime,status) values (" +
            "#{tname},#{starttime},#{endtime},#{bid},#{updatetime},#{status})")
    void addTaskplan(Taskplan taskplan);

    //删除
    @Update("update taskplan set status = 0 where tid = #{tid}")
    void deleteTaskplan(String tid);

    //修改
    @Update("update taskplan set tname=#{tname},starttime=#{starttime},endtime=#{endtime}," +
            "bid=#{bid},updatetime=#{updatetime},status=#{status} where tid = #{tid}")
    void updateTaskplan(Taskplan taskplan);

    //查询所有
    @Results(id = "findAllMap",value = {
            @Result(column = "tid",property = "tid"),
            @Result(column = "tname",property = "tname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "bid",property = "bid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "bid",property = "branch",
                    one = @One(select = "com.qf.dao.BranchDao.findByBid",fetchType = FetchType.EAGER))
    })
    @Select("select * from taskplan where status = 1")
    List<Taskplan> findAll();

}
